<!--设置库存安全阈值-->
<template>
    <el-dialog v-model="dialogVisible" width="500" destroy-on-close draggable align-center :before-close="handleClose">
        <el-form style="margin-top: 40px">
            <el-form-item label="库存阈值">
                <el-input v-model="inventory"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="handleUpdate">
                    更新
                </el-button>
                <el-button @click="handleClose">取消</el-button>

            </div>
        </template>
    </el-dialog>
</template>
<script>
import mdAPI from "../../../util/request-md/mat-pro/mat-pro.js";

export default {
    props: ['visible', 'details'],
    emits: ['callClosed','calledUpdateSuccess'],
    data() {
        return {
            dialogVisible: false,
            inventory:0
        }
    },
    watch: {
        visible(val) {
            this.dialogVisible = val;
            this.inventory = this.details.inventory;
        }
    },
    methods: {
        handleUpdate() {
            let updateStatusParam = {
                id: this.details.id,
                inventory: this.inventory,
                category: this.details.category
            };
            mdAPI.updateInventory(updateStatusParam, ((res) => {
                if (res.code === 200) {
                    this.$message.success("设置成功");
                    this.dialogVisible = false;
                    this.details.inventory = this.inventory;
                    this.$emit('callClosed');
                } else {
                    this.$message.error("网络不佳，请稍后再试");
                }
            }));
        },
        handleClose() {
            this.$emit('callClosed');
        }
    }

}
</script>
<style></style>